// Language registry implementation stub
// TODO: Implement language registry

use codegraph_core::{LanguageAdapter, Result};
use std::collections::HashMap;

pub struct LanguageRegistry {
    adapters: HashMap<String, Box<dyn LanguageAdapter>>,
    extension_map: HashMap<String, String>,
}

impl LanguageRegistry {
    pub fn new() -> Self {
        Self {
            adapters: HashMap::new(),
            extension_map: HashMap::new(),
        }
    }
    
    pub fn register_language(&mut self, adapter: Box<dyn LanguageAdapter>) -> Result<()> {
        let language_id = adapter.language_id().to_string();
        
        // Register file extensions
        for ext in adapter.file_extensions() {
            self.extension_map.insert(ext.clone(), language_id.clone());
        }
        
        self.adapters.insert(language_id, adapter);
        Ok(())
    }
    
    pub fn get_adapter(&self, language_id: &str) -> Option<&dyn LanguageAdapter> {
        self.adapters.get(language_id).map(|a| a.as_ref())
    }
    
    pub fn get_adapter_by_extension(&self, extension: &str) -> Option<&dyn LanguageAdapter> {
        self.extension_map
            .get(extension)
            .and_then(|lang_id| self.adapters.get(lang_id))
            .map(|a| a.as_ref())
    }
    
    pub fn supported_languages(&self) -> Vec<String> {
        self.adapters.keys().cloned().collect()
    }
}

impl Default for LanguageRegistry {
    fn default() -> Self {
        Self::new()
    }
}
